package com.edu.exam.entity.assessment.plan;

import com.edu.exam.enums.assessment.plan.*;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 模板字段定义实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：template_field_definition
 *
 * <p>模板字段定义实体，描述模板中每个字段的详细配置。
 * 包括字段名称、类型、验证规则、默认值、显示顺序等，
     支持动态模板配置和字段扩展。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "template_field_definition")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TemplateFieldDefinition {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 模板ID
     */
    @Column(name = "template_id", nullable = false)
    private Long templateId;

    /**
     * 字段名称
     */
    @Column(name = "field_name", length = 100, nullable = false)
    private String fieldName;

    /**
     * 字段显示名称
     */
    @Column(name = "field_display_name", length = 200, nullable = false)
    private String fieldDisplayName;

    /**
     * 字段类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "field_type", length = 20, nullable = false)
    private FieldType fieldType;

    /**
     * 字段长度
     */
    @Column(name = "field_length")
    private Integer fieldLength;

    /**
     * 是否必填
     */
    @Column(name = "is_required", nullable = false)
    private Boolean isRequired;

    /**
     * 是否只读
     */
    @Column(name = "is_readonly", nullable = false)
    private Boolean isReadonly;

    /**
     * 是否可见
     */
    @Column(name = "is_visible", nullable = false)
    private Boolean isVisible;

    /**
     * 显示顺序
     */
    @Column(name = "display_order")
    private Integer displayOrder;

    /**
     * 默认值
     */
    @Column(name = "default_value", length = 500)
    private String defaultValue;

    /**
     * 验证规则（JSON格式）
     */
    @Column(name = "validation_rules", columnDefinition = "TEXT")
    private String validationRules;

    /**
     * 字段描述
     */
    @Column(name = "field_description", length = 1000)
    private String fieldDescription;

    /**
     * 字段提示
     */
    @Column(name = "field_hint", length = 500)
    private String fieldHint;

    /**
     * 字段分组
     */
    @Column(name = "field_group", length = 100)
    private String fieldGroup;

    /**
     * 字段选项（JSON格式，用于下拉框、单选框等）
     */
    @Column(name = "field_options", columnDefinition = "TEXT")
    private String fieldOptions;

    /**
     * 字段约束
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "field_constraint", length = 20)
    private FieldConstraint fieldConstraint;

    /**
     * 字段格式
     */
    @Column(name = "field_format", length = 100)
    private String fieldFormat;

    /**
     * 最小值
     */
    @Column(name = "min_value")
    private String minValue;

    /**
     * 最大值
     */
    @Column(name = "max_value")
    private String maxValue;

    /**
     * 正则表达式
     */
    @Column(name = "regex_pattern", length = 500)
    private String regexPattern;

    /**
     * 错误提示信息
     */
    @Column(name = "error_message", length = 500)
    private String errorMessage;

    /**
     * 依赖字段
     */
    @Column(name = "dependency_field", length = 100)
    private String dependencyField;

    /**
     * 依赖条件（JSON格式）
     */
    @Column(name = "dependency_condition", columnDefinition = "TEXT")
    private String dependencyCondition;

    /**
     * 计算公式（用于计算字段）
     */
    @Column(name = "calculation_formula", length = 1000)
    private String calculationFormula;

    /**
     * 字段权限
     */
    @Column(name = "field_permissions", length = 200)
    private String fieldPermissions;

    /**
     * 是否系统字段
     */
    @Column(name = "is_system_field", nullable = false)
    private Boolean isSystemField;

    /**
     * 是否启用
     */
    @Column(name = "is_enabled", nullable = false)
    private Boolean isEnabled;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    /**
     * 创建人姓名
     */
    @Column(name = "created_by_name", length = 100)
    private String createdByName;

    /**
     * 更新人ID
     */

    private String updateById;

    /**
     * 更新人名称
     */
    private String updatedByName;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 版本号
     */
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;
}
